function clearTable(tableId) {
    var table = document.getElementById(tableId);
    for (var i = table.rows.length - 1; i >0; i--) {
        table.deleteRow(i);
    }
}

function deleteTableRow(tableId, rowNumber) {
    var table = document.getElementById(tableId);
    if (rowNumber > 0 && rowNumber < table.rows.length) {
        table.deleteRow(rowNumber);
    }
}

function insertTableRow(tableId, cells, rowNumber) {
    var table = document.getElementById(tableId);
    var newRow = table.insertRow(rowNumber);
    var newCell;
    for (var i=0; i < cells.length; i++) {
        newCell = newRow.insertCell(newRow.cells.length);
        newCell.innerHTML = cells[i];
    }
    return newRow;
}

function addTableRow(tableId, cells) {
    var table = document.getElementById(tableId);
    return insertTableRow(tableId, cells, table.rows.length);
}